package core.tech.utilies;

import java.util.UUID;

public class Random {

	public String randomEmail(int characterLength, int digitsLength) {
		String[] domainPreferences = { "com", "in", "org", "edu" };
		String[] separatorPreferences = { ".", "_" };
		String[] mailPreferences = { "yahoo", "gmail", "rediff", "hotmail" };
		String email = randomText(characterLength)
				+ separatorPreferences[_numberRandomizer(0,
						separatorPreferences.length - 1)]
				+ randomNumber(digitsLength)
				+ "@"
				+ mailPreferences[_numberRandomizer(0,
						mailPreferences.length - 1)]
				+ "."
				+ domainPreferences[_numberRandomizer(0,
						domainPreferences.length - 1)];
		return email;
	}

	public String randomText(int textLength) {
		String text = "";
		while (text.length() < textLength) {
			text += (char) _numberRandomizer(65, 90);
		}
		return _stringCaseRandomize(text);
	}

	public String randomNumber(int digitsLength) {
		String number = "";
		while (number.length() < digitsLength) {
			number += _numberRandomizer(0, 9);
		}
		return number;
	}

	private int _numberRandomizer(int minNumber, int maxNumber) {
		int Min = minNumber;
		int Max = maxNumber;
		int rand = Min + (int) (Math.random() * ((Max - Min) + 1));
		return rand;
	}

	private String _stringCaseRandomize(String text) {
		String caseText = "";
		for (int i = 0; i < text.length(); i++) {
			switch (_numberRandomizer(1, 4)) {
			case 1:
				caseText += Character.toString(text.charAt(i)).toLowerCase();
				break;
			case 2:
				caseText += Character.toString(text.charAt(i)).toUpperCase();
				break;
			case 3:
				caseText += Character.toString(text.charAt(i)).toLowerCase();
				break;
			case 4:
				caseText += Character.toString(text.charAt(i)).toUpperCase();
				break;
			default:
				caseText += Character.toString(text.charAt(i)).toLowerCase();
				break;
			}
		}
		return caseText;
	}

	public String generateUUID() {
		return UUID.randomUUID().toString();
	}
}
